<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="128px"
    >
      <el-form-item label="订单编号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="主订单号" prop="mainOrderId">
        <el-input
          v-model="queryParams.mainOrderId"
          placeholder="请输入主订单号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="目的港" prop="unloadingPort">
        <el-input
          v-model="queryParams.unloadingPort"
          placeholder="请输入目的港"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="客户公司" align="center" prop="companyName" />
      <el-table-column label="运单号" align="center" prop="mainOrderId" width="150" />
      <el-table-column label="订单号" align="center" prop="orderId" width="100" />
      <el-table-column label="目的港" align="center" prop="destinationCityName" />
      <el-table-column label="件数" align="center" prop="warehouseNumber" width="60"/>
      <el-table-column label="重量" align="center" prop="weight"  width="100"/>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="airway(scope.row.id)"
            v-hasPermi="['business:cargo-info:airway']"
          >
            航空信息
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
    

  <!-- 表单弹窗：添加/修改 -->
  <FlightDataForm ref="FlightDataFormRef" @success="getList"/>
</template>

<script setup lang="ts">
import { getIntDictOptions, getStrDictOptions, DICT_TYPE } from '@/utils/dict'
import download from '@/utils/download'
import { CargoInfoApi, CargoInfoVO } from '@/api/business/cargoinfo'
import FlightDataForm from './flightDataForm.vue'
import { dateFormatter } from '@/utils/formatTime'
import {useUserStore} from '@/store/modules/user'

/** 货物资料 列表 */
defineOptions({ name: 'FlightDataIndex' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const userStore = useUserStore();


const loading = ref(true) // 列表的加载中
const list = ref<CargoInfoVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  orderId: undefined,
  mainOrderId: undefined,
  unloadingPort: undefined,
  status: 7,
  serviceId:userStore.user.id
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中



/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await CargoInfoApi.getCargoInfoPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}


/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}


const FlightDataFormRef = ref();

const airway = (id:number)=>{
  FlightDataFormRef.value.open(id);
}


/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
